﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;

namespace WebSite.admin.member
{
    public partial class member_rank : BaseAdmin
    {

        // Methods
        private void Bind()
        {
            string sql = "select * from DB_memberank";
            this.GridView1.DataSource = SQLAccess.GreatDs(sql);
            this.GridView1.DataBind();
            if ((base.Request.QueryString["rankid"] != null) && (base.Request.QueryString["action"] != null))
            {
                if (base.Request.QueryString["action"].ToString() == "yess")
                {
                    SQLAccess.DoSql("update DB_memberank set isshow=0 where rankid=" + base.Request.QueryString["rankid"].ToString() + "");
                }
                if (base.Request.QueryString["action"].ToString() == "noo")
                {
                    SQLAccess.DoSql("update DB_memberank set isshow=1 where rankid=" + base.Request.QueryString["rankid"].ToString() + "");
                }
                if (base.Request.QueryString["action"].ToString() == "yes")
                {
                    SQLAccess.DoSql("update DB_memberank set ismember=0 where rankid=" + base.Request.QueryString["rankid"].ToString() + "");
                }
                if (base.Request.QueryString["action"].ToString() == "no")
                {
                    SQLAccess.DoSql("update DB_memberank set ismember=1 where rankid=" + base.Request.QueryString["rankid"].ToString() + "");
                }
                if (base.Request.QueryString["action"].ToString() == "del")
                {
                    SQLAccess.DoSql("delete from DB_memberank where rankid=" + base.Request.QueryString["rankid"].ToString() + "");
                    SQLAccess.DoSql("delete from DB_Memberprice where rankid=" + base.Request.QueryString["rankid"].ToString() + "");
                }
                base.Response.Write("<script language='javascript'>window.location.href='member_rank.aspx';</script>");
                base.Response.End();
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if ((e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.DataRow))
            {
                e.Row.Cells[0].Width = 5;
                CheckBox box = new CheckBox();
                box = (CheckBox)e.Row.FindControl("CheckBox1");
                if (box != null)
                {
                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        e.Row.Cells[1].Width = 180;
                        if (e.Row.Cells[5].Text == "True")
                        {
                            e.Row.Cells[5].Text = "<a href=member_rank.aspx?action=yes&amp;rankid=" + e.Row.Cells[7].Text + "><img src='../images/yes.gif' border='0' /></a>";
                        }
                        else
                        {
                            e.Row.Cells[5].Text = "<a href=member_rank.aspx?action=no&amp;rankid=" + e.Row.Cells[7].Text + "><img src='../images/no.gif' border='0' /></a>";
                        }
                        if (e.Row.Cells[6].Text == "True")
                        {
                            e.Row.Cells[6].Text = "<a href=member_rank.aspx?action=yess&amp;rankid=" + e.Row.Cells[7].Text + "><img src='../images/yes.gif' border='0' /></a>";
                        }
                        else
                        {
                            e.Row.Cells[6].Text = "<a href=member_rank.aspx?action=noo&amp;rankid=" + e.Row.Cells[7].Text + "><img src='../images/no.gif' border='0' /></a>";
                        }
                        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"" + e.Row.Style["BACKGROUND-COLOR"] + "\"");
                        e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"#efefef\"");
                    }
                    if (e.Row.Cells[7].Text.ToString() == "1")
                    {
                        e.Row.Cells[0].Text = "";
                    }
                    else if (e.Row.RowType == DataControlRowType.Header)
                    {
                        box.Attributes.Add("onclick", "SelectAll(this.checked)");
                    }
                    e.Row.Cells[7].Visible = false;
                }
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            for (int i = 0; i <= (this.GridView1.Rows.Count - 1); i++)
            {
                CheckBox box = (CheckBox)this.GridView1.Rows[i].FindControl("CheckBox1");
                if (box.Checked)
                {
                    SQLAccess.DoSql("DELETE FROM DB_memberank where rankid=" + this.GridView1.DataKeys[i].Value + "");
                    SQLAccess.DoSql("DELETE FROM DB_Memberprice where rankid=" + this.GridView1.DataKeys[i].Value + "");
                }
            }
            base.Response.Write("<script language=javascript>window.location.href='member_rank.aspx';</script>");
            base.Response.End();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ImageButton1.Attributes["onclick"] = "return CheckSelect(true,'del');";
            if (!base.IsPostBack)
            {
                this.Bind();
            }
        }


    }
}